<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="js/http2.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .item img{
            width: 140px;
            height: 140px;
            padding: 10px;
        }
        .item{
            float: left;
            border: 1px solid #eee;
            margin-right: 80px;
            margin-left: 20px;
            margin-top: 50px;
        }
    </style>
</head>
<body>
    <div id="app">
        
    </div>
    <script> 
        loadData()
        jump()
        $(window).scroll(function(){
            if(isReachBottom()){
                var offset = $(".item").length
                loadData(offset)
            }
        })
        function jump(){
            setTimeout(()=>{
                $(".item").click(function(event){
                    // console.log(event.currentTarget.dataset.aid);
                    let aid = event.target.dataset.aid;
                    location.href = `27-detail.html?id=${aid}`
                })
            },300)
        }

        function isReachBottom(){
            var scrollTop = $(window).scrollTop()
            var availHeight = $(window).height()
            var dh = $(document).height()
            return (scrollTop+availHeight == dh)?true:false
        }

        function loadData(offset){
            http({
                offset,
                success:res=>{
                    var playlists = res.playlists
                    // console.log(playlists);
                    playlists.forEach(item=>{
                        var template=`
                            <div class="item" data-aid=${item.id}>
                                <img src=${item.coverImgUrl} alt="">
                            </div>
                        `
                        $("#app").append(template)
                    })
                }
            })
        }
    </script>
</body>
</html>